package com.xnyzc.lhy.mis.mapper.user;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xnyzc.lhy.mis.entity.user.OaCUser;
import com.xnyzc.lhy.mis.entity.user.UserInfoManage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户基础表 Mapper 接口
 * </p>
 *
 * @author lhy@xnyzc.com
 * @since 2019-07-17
 */
public interface OaCUserMapper extends BaseMapper<OaCUser> {


    /**
     * 分页获取用户信息
     * @param iPage
     * @param inId
     * @return
     */
    @Select({"<script>  " +
            "SELECT  " +
            "oa_c_user.*, " +
            "oa_c_user_office.office_id  " +
            "FROM  " +
            "oa_c_user, " +
            "oa_c_user_office  " +
            "WHERE  " +
            "oa_c_user.user_id IN   " +
            "<foreach collection='inId' item='item'  index='index' open='(' separator=',' close=')'>   " +
            "#{item}   " +
            "</foreach>  " +
            "AND oa_c_user.user_id = oa_c_user_office.user_id    " +
            "AND  oa_c_user.deleted = 0  " +
            "AND oa_c_user_office.deleted = 0  " +
            "ORDER BY  oa_c_user.create_time DESC  " +
            "</script>"})
    List<UserInfoManage> getUserInfo(IPage iPage, @Param("inId") List<Long> inId);

    /*@Select({"<script>  " +
            "SELECT  " +
            "oa_c_user.*, " +
            "oa_c_user_office.office_id  " +
            "FROM  " +
            "oa_c_user, " +
            "oa_c_user_office  " +
            "WHERE  " +
            "oa_c_user.user_id IN   " +
            "<foreach collection='inId' item='item'  index='index' open='(' separator=',' close=')'>   " +
            "#{item}   " +
            "</foreach>  " +
            "AND oa_c_user.user_id = oa_c_user_office.user_id    " +
            "AND  oa_c_user.deleted = 0  " +
            "AND oa_c_user_office.deleted = 0 " +
            "AND oa_c_user.sex LIKE #{sex}  " +
            "AND oa_c_user.is_blocked LIKE #{is_blocked}  " +
            "AND oa_c_user.user_phone LIKE #{user_phone}  " +
            "AND oa_c_user.user_name LIKE #{user_name}" +
            "AND oa_c_user_office.office_id LIKE #{office_id}" +
            "ORDER BY  oa_c_user.create_time DESC   " +
            "</script>"})*/
    /**
     * 模糊查询获取用户信息
     * @param iPage
     * @param inId
     * @param sex
     * @param isBlocked
     * @param userPhone
     * @param userName
     * @param office_id
     * @return
     */
    List<UserInfoManage> getUserInfoLike(IPage iPage, @Param("inId") List<Long> inId, @Param("sex") String sex, @Param("is_blocked") String isBlocked, @Param("user_phone") String userPhone, @Param("user_name") String userName, @Param("office_id") String office_id, @Param("office_ids") List<Long> officeIds);


    /**
     * 获取数据导出Excel数据
     * @param inId
     * @return
     */
    @Select({"<script>  " +
            "SELECT  " +
            "oa_c_user.*, " +
            "oa_c_user_office.office_id," +
            "oa_c_user_info.identity_number , " +
            "oa_c_user_info.address,  " +
            "oa_c_user_info.emergency_contact,  " +
            "oa_c_user_info.emergency_mobile,   " +
            "oa_c_user_info.emergency_address    " +
            "FROM  " +
            "oa_c_user, " +
            "oa_c_user_office," +
            "oa_c_user_info     " +
            "WHERE  " +
            "oa_c_user.user_id IN   " +
            "<foreach collection='inId' item='item'  index='index' open='(' separator=',' close=')'>   " +
            "#{item}   " +
            "</foreach>  " +
            "AND oa_c_user.user_id = oa_c_user_office.user_id    " +
            "AND  oa_c_user.deleted = 0  " +
            "AND oa_c_user_office.deleted = 0   "       +
            "AND oa_c_user_info.deleted = 0  " +
            "AND oa_c_user.user_id = oa_c_user_info.user_id    " +
            "ORDER BY  oa_c_user.create_time DESC " +
            "</script>"})
    List<UserInfoManage> exportExcelUserInfo(@Param("inId") List<Long> inId);


    /**
     * 获取用户详情
     * @param userId
     * @return
     */
    @Select("SELECT  " +
            "oa_c_user.*, " +
            "oa_c_user_info.info_id, " +
            "oa_c_user_info.age, " +
            "oa_c_user_info.address, " +
            "oa_c_user_info.emergency_contact, " +
            "oa_c_user_info.emergency_mobile, " +
            "oa_c_user_info.emergency_address, " +
            "oa_c_user_info.identity_number, " +
            "oa_c_user_info.identity_address,  " +
            "oa_c_user_info.identity_positive_file_id,  " +
            "oa_c_user_info.identity_other_file_id,      " +
            "oa_c_user_office.office_id,      " +
            "oa_sys_office.name AS officeName      " +
            "FROM  " +
            "oa_c_user,  " +
            "oa_c_user_info,   " +
            "oa_c_user_office,   " +
            "oa_sys_office   " +
            "WHERE  " +
            "oa_c_user.user_id = oa_c_user_info.user_id  " +
            "and oa_c_user.user_id = oa_c_user_office.user_id  " +
            "and oa_sys_office.office_id = oa_c_user_office.office_id  " +
            "and oa_c_user.user_id= #{userId} ")
    UserInfoManage getUserInfoDetails(@Param("userId") Long userId);


    /**
     * 查询是否有信息，没有信息证明手机号没冲突可以修改
     * @param user_phone
     * @return
     */
    @Select("SELECT " +
            "oa_c_user.*  " +
            "FROM  oa_c_user  " +
            "WHERE  oa_c_user.user_phone=#{user_phone} " +
            "AND  oa_c_user.user_id <> #{user_id}")
    List<UserInfoManage> findOaCUserPhone(@Param("user_phone") String user_phone, @Param("user_id") Long user_id);



}
